// TOWN SCRIPT
//    Town 2: Secret Tunnel

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

short i,choice;
short lead_char;

body;

beginstate INIT_STATE;
// This state called whenever this town is entered.
//Names

// Regenerate NPCs
// Klinger ID = 101
// Valzier ID = 300
spawn_creature(6);
spawn_creature(7);
if (get_sdf(110,0) == 10) {
 add_char_to_party(6);
 set_flag(110,0,1);
 print_str_color("Klinger is able to rest and rejoins the party!",3);
}
if (get_sdf(110,1) == 10) {
 add_char_to_party(7);
 set_flag(110,1,1);
 print_str_color("Valzier is able to rest and rejoins the party!",3);
}
erase_char(6);
erase_char(7);

 i = 0;
 while (i < 5) {
  if (char_ok(i)) {
   lead_char = i;
   i = 5;
  }
  else
   i = i + 1;
 }
	
	set_crime_tolerance(1);

break;

beginstate EXIT_STATE;



break;

beginstate START_STATE;
	

break;


beginstate 10;

change_outdoor_location(0,1,33,9);
move_to_new_town(1,23,9);

break;


beginstate 11;

if ((get_sdf(110,0) == 1) && (get_sdf(0,26) == 0)) {
 set_flag(0,26,1);
 reset_dialog();
 add_dialog_str(0,"_It was lucky we were able to find this small system of caverns so close to Vikida. We had to dig some tunnels, but the work was worth it. Our operatives can sneak in and out of the village as needed._",0);
 add_dialog_str(1,"_Notice these runes. They help conceal the tunnel from magical detection. Thus far they seem to have worked. However, we try to limit our use of it to evade detection._",0);
 add_dialog_str(2,"These wards are quite simple and crude, insufficient to conceal this Nephil civilization from the skilled Empire wizards. Another mystery still remains.",0);
 add_dialog_str(3,"Klinger jibes, _If, for some reason, we need to return to Vikida, we can use this passage. As long as we stay out of Arivan's fortress, I should be able to disguise myself well enough._",0);
	add_dialog_choice(0,"OK.");
 choice = run_dialog(1);
}

break;


beginstate 12;

if ((get_sdf(110,0) == 1) && (get_sdf(0,27) == 0)) {
 set_flag(0,27,1);
 message_dialog("_Asmur is a strange tribe, almost as advanced as Vikida, nothing like the barbaric tribes Arivan slaughtered. They were an obvious ally, but when we approached them, they were reluctant to help, or do anything._","_They're very secretive, quite content keeping to their corner of the forest. Couldn't get much out of them. Perhaps Arivan's attack will bring them to our cause. Oh, take a left here._");
}

break;


beginstate 13;

if ((get_sdf(110,0) == 1) && (get_sdf(0,28) == 0)) {
 set_flag(0,28,1);
 message_dialog("_We're almost to the end of the tunnel. We should surface on the other side of the outcropping north of Vikida. From there, we should be able to continue northward until we reach Asmur._","_I hope our warning is enough. Arivan is known to be very cruel with those who cross her. I know first hand. Arivan takes delight in personally inflicting pain upon her more 'worthy' captives. I won't pretend to understand her madness._");
}

break;


beginstate 14;

if ((get_sdf(110,0) == 1) && (get_sdf(0,29) == 0)) {
 set_flag(0,29,1);
 message_dialog("_There! That ladder will take us to the surface. I hope you brought enough food. This will be a nice walk through some rough terrain ahead._","");
 set_town_visibility(2,1);
}

break;